package com.example.navigation.api.login

import com.example.navigation.api.ResponseData
import com.example.navigation.api.TokenInterceptor
import javax.inject.Inject

/**
 * Created with IntelliJ IDEA.
 * @Author: Liao Run
 * @Date: 2024-06-08 10:26
 * @Description:
 **/
class LoginRepository @Inject constructor(
    private val loginApi: LoginApi,
    private val tokenInterceptor: TokenInterceptor
) {

    suspend fun login(loginParams: LoginApi.LoginParams): ResponseData<LoginApi.UserInfo> {
        val responseData = loginApi.login(loginParams)
        // 登录成功保存token
        if (responseData.code == 1) {
            tokenInterceptor.token = responseData.data?.token ?: ""
        }
        return responseData
    }
}